home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6692 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: mail2news.demon.co.uk!besu223.LOCAL
  2. From: Dave Easley <easleydp@ncp.gpt.co.uk>
  3. Newsgroups: comp.lang.c++
  4. Subject: Simple 8-bit integer class not so simple?
  5. Date: Fri, 9 Feb 1996 14:32:25 +0000
  6. Message-ID: <9602091432.AA11113@besu223.LOCAL>
  7. X-NNTP-Posting-Host: besu223.LOCAL
  8. Content-Length: 1883
  9. X-Mail2News-Path: net.gpt.co.uk!cvhp99!besf227!besu223.LOCAL
  10.  
  11. On our project's utilities library provides portable integer types
  12. UtInt8 (8 bit signed integer), UtUint8 (unsigned), UtInt16, etc.
  13.  
  14. No prizes for guesing that the 8 bit ones are typedef'd to signed and
  15. unsigned char. Problem is, some of the users have (understandably)
  16. complained that when they cout one of these, it prints as a char
  17. rather than an integer.
  18.  
  19. So we are going to move to classes for UtInt8 and UtUint8 so we can
  20. tweak the ostream& operator<<(ostream& s, UtInt8 val) behaviour (and
  21. operator>>). All the other behaviour was fine, but once we start using
  22. a class we understand we have to supply all the relational and
  23. arithmatic operators as well.
  24.  
  25. I can see we'll definetly need to provide operator ++ and --. Also all
  26. the standard binary relational and arithmatic ops for the simple case
  27. where it's a UtInt8 on both sides. But I'm unsure what the best
  28. approach is to ensure that expressions where these types are mixed
  29. with other numeric types work as one would expect, e.g.
  30.   [int] < [UtInt8]
  31.   [UtInt8] < [unsigned]
  32.   [UtInt8] * [float]
  33.   etc. (many permutations!)
  34.  
  35. Does anyone know the best way to do this? If we just provide a type
  36. conversion operator to int will this do? I can imagine not because
  37. (considering the [UtInt8] * [float] example) the compiler won't do
  38. more than one implicit type conversion.
  39. If we provide type conv ops for all the fundamental numeric types,
  40. won't this lead to ambiguities in certain cases?
  41.  
  42. TIA for any advice,
  43.  
  44. Dave Easley
  45.  
  46. --
  47. GPT Ltd is not responsible for my opinions.
  48. ***********************************************************
  49. * Dave Easley               * GPT Wisecom Systems         *
  50. * easleydp@ncp.gpt.co.uk    * Technology Drive            *
  51. * Tel: +44 (0) 115 9433348  * Nottingham, UK              *
  52. * Fax: +44 (0) 115 9433805  * NG9 1LA                     *
  53. ***********************************************************
  54.